$NG.AllReady(function (
    editPage,
    { useAction, useValuesChange, useDataIndexChange, useUpdateRow , useClick }
) {
    const mstform = $NG.getCmpApi("p_form_gzdyfbsgj")
    const dgrid = $NG.getCmpApi("p_form_gzdyfbsgj_d")
    // 监听项目选择的变化
    useValuesChange(({args})=>{
        console.log(`监听变化的值合同编号`,args)
    }, "p_form_gzdyfbsgj.u_pc_no")
    // 监听项目选择的变化
    useValuesChange(({args})=>{
     cntDFilter()
     console.log(`监听变化的值合同名称`,args)
     const phID= args[0].phid_pc.PcNo
     $NG.updateState((updater)=>{
         updater.data.p_form_gzdyfbsgj.setProps({
             u_pc_no: phID
         })
     })
     cntMFilter()
     dgrid.clearRows()
    }, "p_form_gzdyfbsgj.phid_pc")
    // 监听表格中合同名称的变化
    useDataIndexChange(({args})=>{
        console.log(`监听表格数据的变化`,args);
        getCntInfo(args)
    },"u_fwygcht_name")
    useDataIndexChange(({args})=>{
        console.log(`监听表格数据的变化`,args);
        $NG.execServer("getGzdyqdByPhid",{phid:args[0].u_gzdy_name},(res)=>{
            const _data = JSON.parse(res.data)[0].extendObjects
            args[0].u_gzdy_no = _data.u_gzdy_code
        })
        dgrid.refreshView()
    },"u_gzdy_name")
    useDataIndexChange(({args})=>{
        console.log(args);
        getGzdynoById(args[0].u_gzdy_name,(code)=>{
            args[0].u_gzdy_no = code
            dgrid.refreshView()
        })
    }, "u_gzdy_name")
    // 根据id获取编码
    function getGzdynoById(phid, fun){
        $NG.execServer("getGzdynoById", {phid},function(res){
            if(res.count == 0) return 
            const _data = JSON.parse(res.data)[0].extendObjects
            fun(_data.u_gzdy_code)
        })
    }
// 根据主类的项目id获取合同
    cntDFilter()
      function cntDFilter() {
        const phid_pcc = $NG.getCmpApi('p_form_gzdyfbsgj').getItem('phid_pc').getValue();
        console.log(`项目id`,phid_pcc);
            if(!phid_pcc){
                return 
            }
            $NG.updateUI(updater => updater.editGrid.p_form_gzdyfbsgj_d.u_fwygcht_name.setProps((p) => {
              return {
                ...p, editor: {
                  ...p.editor,
                  clientSqlFilter: { phid_pc: $NG.getCmpApi('p_form_gzdyfbsgj').getItem('phid_pc').getValue() },
                }
              };
            }));
        }
        cntMFilter()
        function cntMFilter(){
            const phid_pcc = $NG
			.getCmpApi("p_form_gzdyfbsgj")
			.getItem("phid_pc")
			.getValue();
		if (!phid_pcc) {
			return;
		}
		$NG.updateUI((updater) =>
			updater.editGrid.p_form_gzdyfbsgj_d.u_gzdy_name.setProps((p) => {
				return {
					...p,
					editor: {
						...p.editor,
						clientSqlFilter: {
							'm.phid_pc': $NG
								.getCmpApi("p_form_gzdyfbsgj")
								.getItem("phid_pc")
								.getValue(),
						},
					},
				};
			})
		);
        }
        function getCntInfo(arg){
            $NG.execServer(
                "getCntMInfoByPhid",
                { phid: arg[0].u_fwygcht_name },
                function (res) {
                    const datas = JSON.parse(res.data)[0].extendObjects;
                    console.log(`合同：`,datas);
                    //帮助字段赋值
                    arg[0].u_fwygcht_no = datas.pcm_no
                    arg[0].u_wbgys_name = datas.supply_name
                    arg[0].u_wbgys_no = datas.supply_no
                    dgrid.refreshView()
                }
            );
        }

});